package com.taxsearch.controller;

import com.taxsearch.service.TestService;
import com.taxsearch.util.ApiJsonRet;
import com.taxsearch.util.DbUtil;
import com.taxsearch.util.Json;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * FileName: TestController.java
 *
 * @version V1.0
 * Createdate:  2018年8月10日 下午4:57:01
 * @Description: 示例
 * All rights Reserved, Designed By JS-YFB
 * Copyright:   Copyright(C) 2017-2027
 * Company      JS-YFB LTD.
 * @author: 杨陈
 */
@Controller
@RequestMapping("/HotelAndroid")
public class TestController {

    @Resource
    private TestService testService;

    @RequestMapping("/test1.do")
    @ResponseBody
    public Object test1(String data) {
        GsonBuilder gb = new GsonBuilder();
        Gson g = gb.create();
        Map<String, String> map = g.fromJson(data.toString(), new TypeToken<Map<String, String>>() {
        }.getType());
        System.out.println(map.get("removeNum") + "**********");
//		Json json = new Json();
//		List<HashMap<String,String>> res = testService.test1();
//		json.setObj(res);
//		json.setMsg(values);
//		json.setSuccess(true);
//		return json;
        ApiJsonRet api = new ApiJsonRet();
        api.setBody("1111");
        api.setHeaders("22");
        api.setStatusCode("200");
        return api;
    }

    @RequestMapping("/test2.do")
    @ResponseBody
    public Json test2() throws InterruptedException {
        Json json = new Json();
        HashMap<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("parameter1", "123");
        DbUtil.setDb("2");
        json.setObj(testService.test2(parameterMap));
        DbUtil.setDb("1");
        testService.ttt();
        return json;
    }

}
